<?php
class Modeltotalpoints extends Model {
	public function getTotal(&$total_data, &$total, &$taxes) {

		if ($this->config->get('points_status')) {
			$this->load->language('total/points');
		 
			$rewardpoints = $this->customer->getRewardPoints();
			
			if ((float)$rewardpoints) {
				if ($rewardpoints >= ($total*7)) {
					$points = $total*7;						
				} else {
					$points = $rewardpoints;	
				}
			
				if ($points > 0) {
					$total_data[] = array(
						'code'       => 'points',
						'title'      => $this->language->get('text_points'),
						'text'       => $this->currency->format(-$points),
						'value'      => -$points,
						'sort_order' => $this->config->get('points_sort_order')
					);
					
					$total -= ($points/7);
				
				}
			}
		
		}
	}
	
	public function confirm($order_info, $order_total) {
		$this->load->language('total/points');
		
		if ($order_info['customer_id']) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction SET customer_id = '" . (int)$order_info['customer_id'] . "', order_id = '" . $order_info['order_id'] . "', description = '" . $this->db->escape(sprintf($this->language->get('text_order_id'), $order_info['order_id'])) . "', amount = '" . (float)$order_total['value'] . "', date_added = NOW()");				
		}
	}	
}
?>